/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package BUS;

import DAO.ContactDAO;
import DTO.ContactDTO;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author trquanglong
 */
public class ContactBUS {

    public static void deleteAllContacts() {
        try {
            ContactDAO.deleteAllContacts();
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void deleteCompany(String toString) {
        try {
            ContactDAO.deleteCompany(toString);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void deleteContactsOfGroup(String nameGroup) {
        try {
            try {
                ContactDAO.deleteContactsOfGroup(nameGroup);
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void deleteDataFile(String toString) {
        try {
            ContactDAO.deleteDataFile(toString);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void deleteLocation(String location) {
        try {
            ContactDAO.delteteLocation(location);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static ContactDTO getContact(String name) {
        ContactDTO contact = new ContactDTO();
        try {
            contact = ContactDAO.getContact(name);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return contact;

    }
    public static ArrayList<ContactDTO> getListContact() 
    {
        ArrayList <ContactDTO> lstContact = new ArrayList<ContactDTO>();
        try {
            lstContact =  ContactDAO.getListContact();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstContact;
        
    }

    public static void addContactToDatabase(ContactDTO contact){
        try {
            ContactDAO.addContactToDatabase(contact);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    public static void deleteContact(String nameContact){
        try {
            try {
                ContactDAO.deleteContact(nameContact);
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static ArrayList<String> getListCompany(){
        ArrayList<String> lstCompany = new ArrayList<String>();
        try {
            lstCompany = ContactDAO.getListCompany();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstCompany;
    }

    public static ArrayList<ContactDTO> getListContact(String strSQL) {
        ArrayList<ContactDTO> lstContact = new ArrayList<ContactDTO>();
        try {
            lstContact = ContactDAO.getListContact(strSQL);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstContact;
    }

    public static ArrayList<ContactDTO> getListContactOfCompany(String company) {
        ArrayList<ContactDTO> lstContact = new ArrayList<ContactDTO>();
        try {
            lstContact = ContactDAO.getListContactOfCompany(company);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstContact;

    }

    public static ArrayList<ContactDTO> getListContactOfGroup(int idGroup) {
        ArrayList<ContactDTO> lstContact = new ArrayList<ContactDTO>();
        try {
            lstContact = ContactDAO.getListContactOfGroup(idGroup);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstContact;
    }

    public static ArrayList<ContactDTO> getListContactOfLocation(String country) {
        ArrayList<ContactDTO> lstContact = new ArrayList<ContactDTO>();
        try {
            lstContact = ContactDAO.getListContactOfLocation(country);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstContact;
    }
    
    public static ArrayList<String> getListLocation(){
        ArrayList<String> lstLocation = new ArrayList<String>();
        try {
            lstLocation = ContactDAO.getListLocation();
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lstLocation;
    }

    public static ArrayList<String> getListData(){
        ArrayList<String> lstData = new ArrayList<String>();
        lstData = ContactDAO.getListData();
        return lstData;
    }

    public static void updateContact(ContactDTO newContact) {
        try {
            ContactDAO.updateContact(newContact);
        } catch (SQLException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(ContactBUS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }





}
